package cm309.BookingSystem.vm;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class VenueDetailHandler extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int id = Integer.valueOf(req.getParameter("id"));
		System.out.println("id = "+ id);
		try {
			Connection conn = null;
			try {
				conn = VenueDao.getConnection();
				PreparedStatement ps;
				ps = conn.prepareStatement("SELECT * FROM BK_VM_VENUE WHERE ID=?");
				ps.setInt(1, id);
				ResultSet rs = ps.executeQuery();
				Venue venue = new Venue();				
				rs.next();
//				System.out.println("code = "+ rs.getString(1));
//				System.out.println("desc = "+ rs.getString(2));
//				System.out.println("price = "+ rs.getDouble(3));

				venue.setId(rs.getInt(1));
				venue.setName(rs.getString(2));
				venue.setStatus(rs.getInt(3));
//				System.out.println("code = "+ product.getCode());
//				System.out.println("desc = "+ product.getDesc());
//				System.out.println("price = "+ product.getPrice());

				req.setAttribute("venue", venue);
				RequestDispatcher dispatcher = req.getRequestDispatcher("venueDetail.jsp");
				dispatcher.forward(req, resp);
			}catch (SQLException e) {
				e.printStackTrace();
				
			}finally {
				conn.close();
			}
			
		}catch (Exception e){
			e.printStackTrace();
		}			
		
	}
	

}
